package com.edu.exam.enums.common;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 性别枚举
 * 统一管理性别相关状态
 *
 * @author System
 * @version 1.0.0
 */
public enum Gender implements BaseEnum {

    MALE("MALE", "男"),
    FEMALE("FEMALE", "女");

    private final String code;
    private final String description;

    Gender(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public static Gender fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Gender code cannot be null or empty");
        }
        for (Gender value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown Gender code: " + code);
    }

    public static Gender fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Gender description cannot be null or empty");
        }
        for (Gender value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown Gender description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}